# Contributor: Dhruvin Gandhi <contact@dhruvin.dev>
# Maintainer: Dhruvin Gandhi <contact@dhruvin.dev>
pkgname=hledger
pkgver=1.26
pkgrel=0
pkgdesc="Command-line interface for the hledger accounting system"
url="https://hledger.org/hledger.html"
arch="x86_64" # limited by ghc
license="GPL-3.0-only"
makedepends="ghc cabal libffi-dev ncurses-dev"
subpackages="$pkgname-doc $pkgname-bash-completion"
source="https://hackage.haskell.org/package/hledger-$pkgver/hledger-$pkgver.tar.gz
	cabal.project.freeze"

export CABAL_DIR="$srcdir"/cabal

prepare() {
	default_prepare
	cp "$srcdir"/cabal.project.freeze .
}

build() {
	cabal update
	cabal build --prefix=/usr --enable-relocatable
}

check() {
	cabal test
}

package() {
	local ghcver=$(ghc --version | cut -d " " -f 8)
	install -Dm755 \
		"dist-newstyle/build/$arch-linux/ghc-$ghcver/$pkgname-$pkgver/x/$pkgname/build/$pkgname/$pkgname" \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm644 $pkgname.1 "$pkgdir"/usr/share/man/man1/$pkgname.1
	install -Dm644 shell-completion/$pkgname-completion.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
}

sha512sums="
8cadae1989eaebb17375d7a6b9a82c91e3558e09285129468d86a25af083ff255bf3b487672aade3f0ca3955d6746d7f2409999199d2b658d6a5fcd9ef05e14f  hledger-1.26.tar.gz
94870095532566c5d1a48973e83d27f7fbcc867c1b0ca766a6f98ff2461002fc489dfae8e44b492e71328217fb3d85f270166c21c2c520e648dca96747f6ea05  cabal.project.freeze
"
